﻿using System;
using System.Linq;
using iss.sg4210.se18.team6s.jass.DAL.DataAccess.Interfaces;

namespace iss.sg4210.se18.team6s.jass.DAL.DataAccess.MSSQL
{
    public class AdvertiserAccountDAO : ObjectDAO, IAdvertiserAccount
    {
        public IQueryable<AdvertiserAccount> FindAllAdvertiserAccounts()
        {
            return jassEntities.AdvertiserAccounts;
        }

        public AdvertiserAccount GetAdvertiserAccount(Guid userId)
        {
            return jassEntities.AdvertiserAccounts.SingleOrDefault(m => m.UserId == userId);
        }

        public void AddAdvertiserAccount(AdvertiserAccount advertiserAccount)
        {
            jassEntities.AddToAdvertiserAccounts(advertiserAccount);
            Save();
        }

        public void UpdateAdvertiserAccount(AdvertiserAccount advertiserAccount)
        {
            jassEntities.AdvertiserAccounts.ApplyCurrentValues(advertiserAccount);
            Save();
        }

        public void DeleteAdvertiserAccount(Guid userId)
        {
            jassEntities.AdvertiserAccounts.DeleteObject(GetAdvertiserAccount(userId));
            Save();
        }
    }

    public class AdvertiserAccountTopUpLogDAO : ObjectDAO, IAdvertiserAccountTopUpLog
    {
        public IQueryable<AdvertiserAccountTopUpLog> FindAllAdvertiserAccountTopUpLogs()
        {
            return jassEntities.AdvertiserAccountTopUpLogs;
        }

        public AdvertiserAccountTopUpLog GetAdvertiserAccountTopUpLog(int advertiserAccountTopUpLogId)
        {
            return jassEntities.AdvertiserAccountTopUpLogs.SingleOrDefault(m => m.Id == advertiserAccountTopUpLogId);
        }

        public void AddAdvertiserAccountTopUpLog(AdvertiserAccountTopUpLog advertiserAccountTopUpLog)
        {
            jassEntities.AddToAdvertiserAccountTopUpLogs(advertiserAccountTopUpLog);
            Save();
        }

        public void UpdateAdvertiserAccountTopUpLog(AdvertiserAccountTopUpLog advertiserAccountTopUpLog)
        {
            jassEntities.AdvertiserAccountTopUpLogs.ApplyCurrentValues(advertiserAccountTopUpLog);
            Save();
        }

        public void DeleteAdvertiserAccountTopUpLog(int advertiserAccountTopUpLogId)
        {
            jassEntities.AdvertiserAccountTopUpLogs.DeleteObject(GetAdvertiserAccountTopUpLog(advertiserAccountTopUpLogId));
            Save();
        }
    }

}
